package com.sharemarking.wa.platform.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sharemarking.wa.common.entity.Address;
import com.sharemarking.wa.platform.dto.address.AddressListDto;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author dxy
 */
@Repository
public interface AddressMapper extends BaseMapper<Address> {

    @Select("SELECT post_code,id AS addressId,name,mobile,is_default,concat(province,city,area,address) AS addressStr,province,city,area,address FROM sys_address WHERE member_id = #{memberId}  LIMIT #{pageIndex},#{pageSize}")
    List<AddressListDto> getChooseAddress(Map map);

    @Select("SELECT COUNT(*) FROM sys_address WHERE member_id = #{memberId}  LIMIT #{pageIndex},#{pageSize}")
    Integer getChooseAddressTotal(Map map);

    @Update("UPDATE sys_address SET is_default = 0,update_date= NOW() WHERE member_id = #{memberId} AND id != #{addressId}")
    void updateOtherAddressNoDefault(Integer memberId,Integer addressId);

    @Select("SELECT seq_code FROM sys_area WHERE node_name = #{str}")
    String getCodeByArea(String str);
}
